<script type="module" setup>
//引入模块
import {reactive, computed} from 'vue'

const author = reactive({
  name: 'John Doe',
  books: [
    'Vue 2 - Advanced Guide',
    'Vue 3 - Basic Guide',
    'Vue 4 - The Mystery'
  ]
})

//使用一个函数
function hasBook() {
  console.log("hasBook的这个方法")
  return author.books.length > 0 ? 'Yes' : 'No'
}

//一个计算属性
const publishedBooksMessage = computed(() => {
  console.log("publishedBooksMessage")
  return author.books.length > 0 ? 'Yes' : 'No'
})
</script>

<template>
  <div>
    <p>{{ author.name }} 出版过书本嘛?:</p>
    <span>{{ author.books.length > 0 ? 'Yes' : 'No' }}</span>
    <!--方法的调用-->
    <span>{{ hasBook() }}</span>
    <span>{{hasBook()}}</span>
    <!--属性计算的调用方法-->
    <span>{{publishedBooksMessage}}</span>
  </div>
</template>

<style scoped>
</style>